import { SET_AVATAR } from '../constant';

interface Action {
  type: string;
  data: string;
}

const articleContext = require.context(
  './md',
  false,
  /[0-9]\.md$/
);
let articleId = 1;

const articlePaths = articleContext
  .keys()
  .map((item, index) => {
    const des = item.split('-');
    // console.log(des);

    return {
      _id: index,
      tag: ['xxx', 'xxx'],
      date: des[1].replace('.md', ''),
      title: des[0].replace('./', ''),
      content: articleContext(item).default,
    };
  });

const initState = articlePaths;

export default function addReducer(preState = initState, action: Action) {
  const { type, data } = action;
  switch (type) {
    case SET_AVATAR:
      return data;
    default:
      return preState;
  }
}
